<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                template="/WEB-INF/layout/template.xhtml">

    <f:metadata>
        <f:viewParam name="userId" value="#{userEdit.userId}"/>
        <f:event type="javax.faces.event.PreRenderViewEvent" listener="#{userEdit.beginConversation}"/>
    </f:metadata>

    <ui:define name="content">
        <h:form id="userEditForm">
            <p:panel>
                <f:facet name="header">
                    <h:outputText class="ui-icon ui-icon-person" style="display: inline-block"/>
                    <h:outputText value="添加/修改用户信息"/>
                </f:facet>

                <h:panelGrid columns="2" columnClasses="grid-title, grid-normal">
                    <h:outputText value="用户ID："/>
                    <h:outputText value="#{userEdit.user.userId}"/>

                    <p:outputLabel for="username" value="用户名："/>
                    <p:inputText id="username"
                                 value="#{userEdit.user.username}"
                                 size="10"
                                 required="true"
                                 requiredMessage="必须输入用户名"/>

                    <p:outputLabel for="password" value="口令："/>
                    <h:panelGroup>
                        <p:password id="password"
                                     value="#{userEdit.user.password}"
                                     size="10"
                                     required="true"
                                     requiredMessage="必须输入口令"
                                     rendered="#{not userEdit.managed}"/>
                        <h:outputText value="(隐藏)" rendered="#{userEdit.managed}"/>
                    </h:panelGroup>

                    <p:outputLabel for="realName" value="真实姓名："/>
                    <p:inputText id="realName"
                                 value="#{userEdit.user.realName}"
                                 size="10"
                                 required="true"
                                 requiredMessage="必须输入真实姓名"/>

                    <p:outputLabel for="sex" value="性别："/>
                    <p:selectOneMenu id="sex"
                                     value="#{userEdit.user.sex}"
                                     required="true"
                                     requiredMessage="必须输入性别">
                        <f:selectItems value="#{appResource.getSysCodeList('性别')}"
                                       var="v_sysCode"
                                       itemValue="#{v_sysCode.codeValue}"
                                       itemLabel="#{v_sysCode.codeName}"/>
                    </p:selectOneMenu>

                    <p:outputLabel for="birthday" value="生日："/>
                    <p:calendar id="birthday"
                                value="#{userEdit.user.birthday}"
                                locale="zh_CN"
                                navigator="true"
                                pattern="yyyy-MM-dd"
                                showButtonPanel="true"
                                showWeek="true"
                                size="10"/>

                    <p:outputLabel for="enabled" value="是否启用："/>
                    <p:inputSwitch id="enabled"
                                   value="#{userEdit.user.enabled}"
                                   onLabel="启用"
                                   offLabel="禁用"/>

                    <p:outputLabel for="remark" value="备注："/>
                    <h:panelGroup>
                        <p:inputTextarea id="remark"
                                         value="#{userEdit.user.remark}"
                                         rows="5"
                                         cols="40"
                                         maxlength="500"
                                         counter="remarkCounter"
                                         counterTemplate="还可输入{0}个字符"
                                         autoResize="false"/>
                        <p:tooltip id="remarkCounter"
                                   for="remark"
                                   showEffect="slide"
                                   hideEffect="slide"
                                   trackMouse="true"/>
                    </h:panelGroup>

                    <h:outputText value="创建时间："/>
                    <h:outputText value="#{userEdit.user.createTime}">
                        <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/>
                    </h:outputText>

                    <h:outputText value="创建时间："/>
                    <h:outputText value="#{userEdit.user.createTime}">
                        <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/>
                    </h:outputText>

                    <h:outputText value="更新时间："/>
                    <h:outputText value="#{userEdit.user.updateTime}">
                        <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/>
                    </h:outputText>

                    <h:outputText value="版本："/>
                    <h:outputText value="#{userEdit.user.version}"/>
                </h:panelGrid>

                <f:facet name="footer">
                    <h:panelGrid columns="2">
                        <p:commandButton value="确定"
                                         action="#{userEdit.save}"
                                         icon="ui-icon-check"/>
                        <p:commandButton value="取消"
                                         action="#{userEdit.cancel}"
                                         icon="ui-icon-close"
                                         immediate="true"/>
                    </h:panelGrid>
                </f:facet>
            </p:panel>
        </h:form>
    </ui:define>
</ui:composition>
